<!--
 * @Description: 
 * @version: 
 * @Author: liurui
 * @Date: 2024-02-05 14:01:33
 * @LastEditors: 
 * @LastEditTime: 2024-02-05 14:10:19
-->
<template>
    <div>

    </div>
</template>

<script setup lang="ts">
// 计算字符串的长度，类似于 String#length 

type LengthOfString<S extends string, Arr extends any[] = []> = 
    // 遍历字符，将字符串转换为数字数组
    S extends `${infer First}${infer Rest}` ? 
    // 通过内置方法计算arr长度
    LengthOfString<Rest, [...Arr, 1]> : Arr['length']

type str = "hello world"

type res = LengthOfString<str> // 应推导出 11
</script>

<style scoped>

</style>